import axios from 'axios'
import {
	nanoid
} from 'nanoid'
//人员管理相关的配置
const personOptions = {
	namespaced: true,
	actions: {
		addPersonWang(context, value) {
			if (value.name.indexOf('王') === 0) {
				context.commit('ADD_PERSON', value)
			} else {
				alert('他不姓王')
			}
		},
		addPersonServer(context) {
			axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
				responese => {
					context.commit('ADD_PERSON', {
						id: nanoid(),
						name: responese.data
					})
				},
				error => {
					alert(error.message)
				}
			)
		}
	},
	mutations: {
		ADD_PERSON(state, value) {
			state.personList.unshift(value)
		}
	},
	state: {
		personList: [{
			id: '001',
			name: '邹宜臻'
		}]
	},
	getters: {
		firstPersonName(state) {
			return state.personList[0].name
		}
	}
}
export default personOptions
